﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Compilation;
using System.Web.SessionState;
using System.Web.UI;
using WinnerCMS.BLL;
using WinnerCMS.BLL.Rights;
using WinnerCMS.Common;

namespace WinnerCMS.HttpHandlers
{
    /// <summary>
    /// 权限检查
    /// </summary>
    /// <remarks>IReadOnlySessionState、IRequiresSessionState</remarks>
    public class LoginedChecker : IHttpHandler, IReadOnlySessionState
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string path = context.Request.Path;
            if (MyCollections.Contain(path, RightsControlManage.HuLue) == false)
            {
                if (!context.User.Identity.IsAuthenticated)
                {
                    context.Response.Redirect(context.Request.CurrentExecutionFilePath.Substring(0, context.Request.CurrentExecutionFilePath.LastIndexOf("/") + 1) + "Login.aspx");
                }
                else
                {
                    RightsControlManage.CheckUrlAccess(context);
                }
            }

            IHttpHandler hander = BuildManager.CreateInstanceFromVirtualPath(path, typeof(Page)) as IHttpHandler;
            if (hander != null)
            {
                hander.ProcessRequest(context);
            }
        }
        #endregion
    }
}
